<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>添加修改页面</title>
    <!--引入CSS样式文件-->
    <link rel="stylesheet" href="../../static/lib/layui-v2.6.3/css/layui.css">
</head>

<body>

    <form action="" method="get" class="layui-form" >
        <div class="layui-form-item" >
            <label class="layui-form-label"></label>
            <div class="layui-input-inline">
                <input type="hidden" id="id" name="id"  class="layui-input">
            </div>
        </div>

        <div class="layui-form-item" >
            <label class="layui-form-label">书名</label>
            <div class="layui-input-inline">
                <input type="text" id="name" name="name"  class="layui-input">
            </div>
        </div>


        <div class="layui-form-item">
            <label class="layui-form-label">作者</label>
            <div class="layui-input-inline">
                <input type="text" id="author" name="author" class="layui-input"/>
            </div>
        </div>


        <div class="layui-form-item">

            <div class="layui-inline">

                <label class="layui-form-label">价格</label>
                <div class="layui-input-inline" style="width: 12%">
                    <input type="text" id="price" name="price" class="layui-input"/>
                </div>


                <label class="layui-form-label">销量</label>
                <div class="layui-input-inline" style="width: 12%">
                    <input type="text" id="sales" name="sales"  class="layui-input"/>
                </div>

                <label class="layui-form-label">库存</label>
                <div class="layui-input-inline" style="width: 12%">
                    <input type="text" id="stocks" name="stocks"  class="layui-input"/>
                </div>

            </div>
        </div>

        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">封面</label>
                <div class="layui-inline">
                    <div class="layui-input-inline">
                        <input type="text" id="imgPath" name="imgPath"  class="layui-input"/>
                    </div>
                </div>
            </div>
        </div>

        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">出版日期</label>
                <div class="layui-inline">
                    <div class="layui-input-inline">
                        <input type="text" id="createTime" name="createTime" class="layui-input"/>
                    </div>
                </div>
            </div>
        </div>

        <div class="layui-form-item">
            <div class="layui-input-block">
                <!--lay-filter="formDemo" 绑定按钮事件操作-->
                <button name="but"  lay-submit class="layui-btn" lay-filter="saveBtn">提交</button>
                <button name="set" class="layui-btn">重置</button>
            </div>
        </div>

    </form>

    <script src="../../static/lib/layui-v2.6.3/layui.js" charset="UTF-8" ></script>
    <script scr="../../static/js/lay-config.js?v=1.0.4" charset="UTF-8" ></script>

    <script>
        /**use函数用于加载页面要使用的模块*/
        layui.use(['layer', 'form', 'table'], function() {
            var layer = layui.layer,
                form = layui.form,
                table = layui.table,
                $ = layui.$;
                //加入日期主键
                laydate = layui.laydate;
            laydate.render({
                elem: "#createTime",
                type: "date",
            });
            form.on('submit(saveBtn)',function (data) {

                console.log("=====>"+JSON.stringify(data.field));


                if (data.field.id == null){
                    $.ajax({
                        type: "post",
                        url: "/book/saveBean",
                        dataType: "json",
                        data: JSON.stringify(data.field),
                        contentType: "application/json;charset=UTF-8",
                        success: function (data) {
                            if (data.code == 0){
                                layer.msg(data.message,{icon:6,time:3000},function () {
                                    //加定时器，
                                    setTimeout(function () { layer.closeAll();},3000);
                                    //重新加载父页面信息
                                    parent.location.reload();
                                });
                                //window.location.href="/book/listBook";
                            }else {
                                layer.msg(data.message,{icon:5,time:3000},function () {
                                    //加定时器，
                                    setTimeout(function () { layer.closeAll();},3000);
                                    //重新加载父页面信息
                                    parent.location.reload();
                                });
                            }


                        }
                    });
                }else{
                    console.log(data.field.id);
                    $.ajax({
                        type: "post",
                        url: "/book/editBean",
                        dataType: "json",
                        data: JSON.stringify(data.field),
                        contentType: "application/json;charset=UTF-8",
                        success: function (data) {
                            if (data.code == 0){
                                layer.msg(data.message,{icon:6,time:500},function () {
                                    //加定时器，
                                    setTimeout(function () { layer.closeAll();},1000);
                                    //重新加载父页面信息
                                    parent.location.reload();
                                });
                                //window.location.href="/book/listBook";
                            }else {
                                layer.msg(data.message,{icon:5,time:500},function () {
                                    //加定时器，
                                    setTimeout(function () { layer.closeAll();},1000);
                                    //重新加载父页面信息
                                    parent.location.reload();
                                });
                            }


                        }
                    });
                }







                return false;
            })


        })

    </script>


</body>
</html>